When I use float.IsFinite(float f) in a C# shell, I have no problems. However, when I use it in the context of Unity, I get an error alleging that it is not defined:
Here is the relevent code:
public static bool IsFinite(Unit u) => float.IsFinite(u.blocks);
Unit is a struct in which I wrote the above line.
My question is: why does this error appear and how can I fix it?
float.IsFinite exists in .NET 5, .NET Standard 2.1 and .NET Core 2.1. However Unity supports neither of those frameworks, just .NET Standard 2.0. This is why you cannot use the function here.
However it´s easy to create a workaround for the lack of that function:
public static bool IsFinite(Unit u) => !float.IsInfinity(u.blocks)
There´s an angoing discussion at Unitity support forum about .NET 5